/*
 * @Author: @yzcheng
 * @Date: 2021-04-01 09:14:34
 * @Version: 1.0
 * @LastEditors: @yzcheng
 * @Description:
 * @LastEditTime: 2021-04-01 13:54:33
 */
import { createI18n } from 'vue-i18n'
import enLocale from 'element-plus/lib/locale/lang/en'
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
import code from './code.json'
import ich from './ch.js'
import roadbed_ch from './roadbed.ch.js'
import ien from './en.js'
import table from './table.json'
import form from './form.json';
import operate from './operate.json'
import placeholder from './placeholder.json'
import validate from './validate.json'
import message from './message.json'
import road from './road.json'
const en = {
  code: code['en'],
  table: table['en'],
  form: form['en'],
  operate: operate['en'],
  placeholder: placeholder['en'],
  validate: validate['en'],
  message: message['en'],
  road: road['en'],
  ...ien,
}

const zh = {
  code: code['zh-cn'],
  table: table['zh-cn'],
  form: form['zh-cn'],
  operate: operate['zh-cn'],
  placeholder: placeholder['zh-cn'],
  validate: validate['zh-cn'],
  message: message['zh-cn'],
  road: road['zh-cn'],
  ...roadbed_ch,
  ...ich,
}

const messages: any = {
  [enLocale.name]: {
    // el 这个属性很关键，一定要保证有这个属性，
    ien,
    el: enLocale.el,
    // 定义您自己的字典，但是请不要和 `el` 重复，这样会导致 ElementPlus 内部组件的翻译失效.
    lang: en,
  },
  [zhLocale.name]: {
    ich,
    el: zhLocale.el,
    // 定义您自己的字典，但是请不要和 `el` 重复，这样会导致 ElementPlus 内部组件的翻译失效.
    lang: zh,
  },
  testLocale: {
    el: {},
    // 没有定义 message 字段，会 fallback 回到 en 去, fallbackLocale 的定义在下方 👇
  },
}

const i18n = createI18n({
  locale: zhLocale.name,
  silentTranslationWarn: true, // 取消控制台warning
  silentFallbackWarn: true, // 取消控制台warning
  fallbackLocale: zhLocale.name,
  messages,
})

export const t = i18n.global.t
export const locale = i18n.global.locale

export default i18n
